/*
 * Copyright (c) 2017. pokermman Inc. All rights reserved.
 */

package com.ziqing.apeletnews.retrofit;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by ywh on 2018/5/1.
 */

public class CommonInterceptor implements Interceptor {

    private String token;
    public CommonInterceptor(){
        token = "";
    }
    @Override
    public Response intercept(Chain chain) throws IOException {
        //TODO 添加统一token
        token = "";

        Request oldRequest = chain.request();

        HttpUrl.Builder authorizedUrlBuilder = oldRequest.url()
                .newBuilder()
                .scheme(oldRequest.url().scheme())
                .host(oldRequest.url().host())
                .addQueryParameter("token",token);

        Request newRequest = oldRequest.newBuilder()
                .method(oldRequest.method(),oldRequest.body())
                .url(authorizedUrlBuilder.build())
                .build();
        return chain.proceed(newRequest);
    }
}
